package com.foursquare.stats;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;

import com.foursquare.stats.model.UserRank;
import com.foursquare.stats.model.UserStats;

/**
 * @author Nick Burton (charlesnicholasburton [at] gmail.com)
 */
public class WidgetProviderMedium extends AppWidgetProvider {
	
	@Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,
            int[] appWidgetIds) {
    	Intent intent = new Intent(context, UpdateServiceMedium.class);
        context.startService(intent);
    }
	
	public static class UpdateServiceMedium extends UpdateService {
		
		@Override
		protected void setLayoutResources() {
			mLayoutResource = R.layout.widget_layout_medium;
			mLayoutId = R.id.widget_medium;
			mWidgetProviderClass = WidgetProviderMedium.class;
			mUpdateServiceClass = UpdateServiceMedium.class;
		}

		@Override
		protected void updateUserStats(RemoteViews updateViews, UserStats userStats) {
			updateViews.setTextViewText(R.id.badge_count_medium, userStats.getBadgeCount());
		    updateViews.setTextViewText(R.id.mayor_count_medium, userStats.getMayorCount());
		    updateViews.setTextViewText(R.id.venue_medium, userStats.getVenue());
		}
		
		@Override
		protected void updateUserRank(RemoteViews updateViews, UserRank userRank) {
			updateViews.setTextViewText(R.id.user_rank_medium, userRank.getUserRank());
	        updateViews.setTextViewText(R.id.checkins_medium, userRank.getCheckins());
		}
		
		@Override
		protected void addOnClickIntents(RemoteViews updateViews, Context context){
            
			Intent intent = new Intent(context, TestActivity.class);
            PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
			updateViews.setOnClickPendingIntent(R.id.user_rank_medium, pendingIntent);
			
			intent = new Intent(context, TestActivity.class);
            pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
            updateViews.setOnClickPendingIntent(R.id.mayor_count_medium, pendingIntent);
            
            intent = new Intent(context, TestActivity.class);
            pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
            updateViews.setOnClickPendingIntent(R.id.badge_count_medium, pendingIntent);
            
            intent = new Intent(context, TestActivity.class);
            pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
            updateViews.setOnClickPendingIntent(R.id.checkins_medium, pendingIntent);
		}
	}
}
